var pwd = document.getElementById("pwd");
var username = document.getElementById("name");

var flag1 = false;
var flag2 = false;

username.onblur = function(){Usercheck()};
pwd.onblur = function(){Pwdcheck()};

function Usercheck(){

	var reg_user=/^[a-zA-Z]{3,8}$/;
	var user_result = reg_user.exec(username.value);
	if(!user_result){
		document.getElementById("userError").innerHTML="<font color='red' size='3px'>请输入正确的用户名</font>";
	}else{
		document.getElementById("userError").innerHTML="<font color='grenn' size='3px'>输入正确</font>";
		flag1 = true;
	}
}
function Pwdcheck(){
	
	var reg_pwd=/^[a-zA-Z0-9]{6,13}$/;
	var pwd_result = reg_pwd.exec(pwd.value);
	if(!pwd_result){
		document.getElementById("pwdError").innerHTML="<font color='red' size='3px'>&nbsp;请输入正确的密码</font>";
	}else{
		document.getElementById("pwdError").innerHTML="<font color='grenn' size='3px'>&nbsp;输入正确</font>";
		flag2 = true;
	}
}

function loginSubmitcheck(){
	var flag3 = false;
	var flag4 = false;
	var reg_user=/^[a-zA-Z]{3,8}$/;
	var user_result = reg_user.exec(username.value);
	if(user_result){
		flag3 = true;
	}
	var reg_pwd=/^[a-zA-Z0-9]{6,13}$/;
	var pwd_result = reg_pwd.exec(pwd.value);
	if(pwd_result){
		flag4 = true;
	}
	if(!flag3){
		document.getElementById("userError").innerHTML="<font color='red' size='3px'>请输入正确的用户名</font>";
		return false;
	}else if(!flag4){
		document.getElementById("pwdError").innerHTML="<font color='red' size='3px'>&nbsp;请输入正确的密码</font>";
		return false;
	}else if(flag3&&flag4){
		return true;
	}
	return true;
}

$(document).ready(function(){
	$("#name").blur(function(){
		Usercheck();
		var name = $("#name").val();
		$.ajax({
			type : "POST",
			url : "/B2CShop/CheckUser",
			async : false,
			cache : false,
			data : {
				name : name
			},
			dataType : "json",
			success : function(result) {
				if (!result) {
					document.getElementById("userError").innerHTML = "<font color='red' size='3px'>&nbsp;用户名不存在</font>";
					return false;
				} else {
					document.getElementById("userError").innerHTML = "<font color='green' size='3px'>&nbsp;输入正确</font>";
					return true;
				}
			}
		});
	});
});
